package a07_二叉树;

/**
 * <p>
 * a04_翻转二叉树
 * </p>
 *
 * @author flyduck
 * @since 2024-08-26
 */
public class a06_翻转二叉树复习0 {

    //     1
    //  2     3
    //4   5 6   7
    //     1
    //  3     2
    //7   6 5   4
    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        invertTree(root.left);
        invertTree(root.right);
        reverse(root);
        return root;
    }

    public void reverse(TreeNode node){
        TreeNode temp = node.left;
        node.left = node.right;
        node.right = temp;
    }


}
